package com.spark.lola.logistics.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spark.lola.logistics.entity.CarInfo;
import com.spark.lola.support.mybatis.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * @author: Zhi-peng wang
 * @date: 2020/04/24 13:07
 * 车辆信息mapper
 **/
@Mapper
public interface CarInfoMapper extends BaseMapper<CarInfo> {

    /**
     * @description: 分页查询车辆信息
     * @author: wzp
     * @date: 2020/4/24
     */
    IPage<CarInfo> findPage(Page<CarInfo> page, @Param(Constants.WRAPPER) Wrapper<CarInfo> wrapper);

    @Select("select is_bind from logistics_car_info where id=#{id}")
    int findIsBindById(long id);

    @Update("update logistics_car_info set is_bind=#{isBind} where id=#{id}")
    int updateIsBindById(int isBind, long id);

    @Select("select no from logistics_car_info where id=#{id}")
    String findNoById(long id);

    @Select("select count(*) from logistics_car_info where used=#{used}")
    int countByUsed(String used);

    int countNo(String no, Long id);

    int countWarn(int warnType, Date indate);

    @Select("select id from logistics_car_info")
    List<Long> findAllId();

    @Select("select mileage from logistics_car_info where id=#{id}")
    Integer findMileageById(long id);

    @Update("update logistics_car_info set mileage=#{mileage} where id=#{id}")
    int updateMileageById(int mileage, long id);

}
